home *** CD-ROM | disk | FTP | other *** search
- ##
- ## $Id: makedef.ksh 1.6 94/01/22 13:41:19 ETIENNE Exp Locker: ETIENNE $
- ############################################################################
- ## (c) A.T.L.P. by Etienne Rossignon
- ## 15 rue du Buisson aux Fraises
- ## F-91741 Massy Cedex
- ## France
- ## Tel : 33 - 1 - 69 30 75 75
- ## Fax : 33 - 1 - 69 30 22 42
- ## CompuServe 100277,2305
- ##
- ## (please:do not remove this note)
- ############################################################################
- ##
- ## DEFINING AN DLL EXPORT FILE FOR C++
- ## see usage functions to know how to use this script
- ##
- ############################################################################
- ## $Log: makedef.ksh $
- # Revision 1.6 94/01/22 13:41:19 ETIENNE
- # remove bug that make the script stop when definition do not exit.
- #
- # Revision 1.5 94/01/16 18:14:28 ETIENNE
- # add on-line options (-d -n and -f )
- #
- # Revision 1.4 94/01/16 15:24:47 ETIENNE
- # now handle relative pathname (thank to MKS support inquiry@mks.com)
- #
- # Revision 1.3 94/01/08 14:14:39 ETIENNE
- # now get obj file name from a list.
- # add usage functions
- # add functions to handle MKS revision
- #
- # Revision 1.2 93/12/22 14:12:17 ETIENNE
- # improve numbering method
- #
- # Revision 1.1 93/06/12 14:10:25 ETIENNE
- # Initial revision
- #
-
- ##
- ## Helper Functions
- ##
- ##
- ############################################################################
- ##
- ## Awk script to handle pathname
- ## usage: to replace \ with / : awk -v dest="sh" "$awk_path"
- ## to replace / with \\ : awk -v dest="dos" "$awk_path"
- ##
- ############################################################################
- ##
- awk_path='BEGIN { slash = "/" ; bslash = "\\\\" }
- function bslash_path(path)
- {
- gsub(slash, "\\\\\\", path)
- return path
- }
- function slash_path(path)
- {
- gsub( bslash, "/", path)
- return path
- }
- {
- if (dest=="sh")
- print slash_path($1);
- else
- print bslash_path($1)
- endif
- }
- '
- ##
- ######################################################################
- ## bslash_path : replace slash in $1 with doubled backslask
- ## and echo the result to stdout
- ######################################################################
- ##
- function bslash_path
- {
- echo $1 | awk -v dest="dos" "$awk_path"
- }
- ##
- ######################################################################
- ## Usage
- ######################################################################
- ##
- function usage {
- echo "USAGE :"
- echo ' makedef <opts> <libname> [ [ -f <listfile> | <objectfile> ]...]'
- echo
- echo '<opts> :'
- echo ' -d : output some debug info '
- echo ' -n : force to use directly the nm on object file '
- echo ' do not perform the MKS version test'
- echo '<libname> : name of dll to create : this is the root name'
- echo ' do not specify extension'
- echo '-f <listfile> : file that contains all object files to analyse'
- echo ' (ie : created with the command ls *.obj > listobj)'
- echo ' *.obj can be given with a relative path'
- echo ' (ie : ..\\foo.obj or ../bar/foo.obj are CORRECT file name)'
- echo ' this sequence can appears any number of time'
- echo ' <objectfile> : specify an object to analyse'
- }
- ##
- ############################################################################
- ## _GetMangledNameOldMKS
- ## Version for Old MKS :
- ## o use this function if your nm version do not recognize new .OBJ FILE
- ## but can analyse correctly library file.
- ## o this function create a temp. lib to old the specify .obj files ($1)
- ## and extract mangled name from the .lib file.
- ############################################################################
- ##
- function _GetMangledNameOldMKS
- {
- #
- # Create a dummy librairy
- #
- dosname=`bslash_path $1`
- echo ${dosname}.lib > tmp.tmp
- echo y >> tmp.tmp
- echo +${dosname}.obj >> tmp.tmp
- echo >> tmp.tmp
-
- LIB /nologo < tmp.tmp > NULL
- #
- # Extract external functions
- #
- nm $1.lib | grep -v 0:0000 | grep \? > $2
-
- #
- # destruction de lib & tmp
- #
- rm $1.lib tmp.tmp
- }
- ##
- ############################################################################
- ## _GetMangledNameNewMKS
- ## Version for New MKS (version 4 and sup)
- ## o used if the MKS toolkit recognize the .OBJ format
- ############################################################################
- ##
- function _GetMangledNameNewMKS
- {
- nm $1.obj | grep -v 0:0000 | grep \? > $2
- }
- ##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- ## START
- ##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- ##
- ## command options analyse
- ##
- filelist=tmpflist.tmp
- debug=no
- forceNewNM=no
- if test $# -lt 2
- then
- usage
- exit -2
- fi
-
- nextcommand=none
- nb=1
- if test -f $filelist; then;rm $filelist;fi
- for i in $*
- do
- {
- if test "$debug" = "yes" ; then; echo CURRENT ARGUMENT = $i ; fi
- case $nextcommand in
- "none" ) {
- case $i in
- "-n" ) forceNewNM=yes ;;
- "-f" ) nextcommand=getlistfile ;;
- "-d" ) debug=yes ; nextcommand=none ;;
- * ) {
- if test $nb -eq 1 ;then
- deffileroot=$i
- else
- if ! ( test -f $i )
- then
- echo file \<$i\> not found
- exit -2
- else
- echo $i >> $filelist
- fi
- let nb=$nb+1
- fi
- } ;;
- esac
- } ;;
- "getlistfile" ) {
- file=$i
- if ! ( test -f $file )
- then
- echo list of object \<$file\> not found
- exit -2
- fi
- for f in $(cat $i | awk -v dest="sh" "$awk_path" )
- do
- if test "$debug" = "yes" ; then; echo testing $f ; fi
- if ! ( test -f $f )
- then
- echo file \<$f\> in file \<$i\> not found
- exit -2
- fi
- done
- echo $(cat $i | awk -v dest="sh" "$awk_path" ) >> $filelist
- nextcommand=none
- } ;;
- esac
- }
- done
-
-
- ############################################################################
- # Choose Mangled Function
- ############################################################################
- MKSVER=`cat $ROOTDIR/product.cfg | grep -i Toolkit | awk '{ print $1 }'`
- if ( test $[MKSVER+0] -le 3 ) && ( test $forceNewNM = "no" )
- then
- echo ------------------------------------
- echo $MKSVER : Old Version
- echo ------------------------------------
- GetMangledNameFunc=_GetMangledNameOldMKS
- else
- echo ------------------------------------
- echo $MKSVER : New Version
- echo ------------------------------------
- GetMangledNameFunc=_GetMangledNameNewMKS
- fi
- ###########################################################################
- ## Test Arguments
- ###########################################################################
- deffile=${deffileroot:?Must Specify Definition File}.def
- rm -i $deffile
- mangledfile=mangled.tmp
- ############################################################################
- ## write .DEF header
- ############################################################################
- #echo LIBRARY $1 > $deffile
- echo LIBRARY > $deffile
- echo EXETYPE WINDOWS >> $deffile
- echo CODE PRELOAD MOVEABLE DISCARDABLE >> $deffile
- echo DATA PRELOAD MOVEABLE SINGLE >> $deffile
- echo HEAPSIZE 1024 >> $deffile
- echo EXPORTS >> $deffile
- echo WEP PRIVATE >> $deffile
- ###########################################################################
- ## debut de la numerotation
- nb=10
- #echo $GetMangledNameFunc
- for i in $(cat $filelist)
- do {
-
- # echo DOSPATH1=$i | awk -v dest="dos" "$awk_path"
- # echo DOSPATH2= `bslash_path $i`
-
- rootname=${i%.obj}
- print -n CURRENT FILE : $i
- #
- # extract mangled name
- #
- $GetMangledNameFunc $rootname $mangledfile
- #
- # Append to .DEF FILE
- #
- echo ";------------------------------------------------------------" $rootname >> $deffile
- aww="{ print \" \" \$3 \" @\"num \" NONAME\" ; num=num+1 }"
- cat $mangledfile | awk -v num=$nb "$aww" >> $deffile
- #
- # Calculate Increment
- #
- increment=`cat $mangledfile | wc | awk '{ print $1 }'`
- print "\t... : $increment exported func."
- nb=$[nb + increment]
- }
- done
- rm $mangledfile
- if test -f $filelist; then;rm $filelist;fi
- ###############################################################
- ## thank's to MKS support that gave me the method
- ## to convert DOS full path name to ksh name as a awk script
- ###############################################################
- ## BEGIN { slash = "/" ; bslash = "\\\\" }
- ## function bslash_path(path)
- ## {
- ## gsub(slash, "\\", path)
- ## return path
- ##}
- ##
- ##function slash_path(path)
- ##{
- ## gsub( bslash, "/", path)
- ## return path
- ##}
- ##{ print slash_path($1); print bslash_path($1) }
-
-